package android.slc.module.sys.ui.dict.type

import android.slc.appbase.api.slc.callback.po.SlcEntity
import android.slc.appbase.ui.vd.BaseListPageVmBoxByFx
import android.slc.appdb.core.DbEntityMaster
import android.slc.appdb.sys.entity.CsDictType
import android.slc.appdb.sys.service.CsDictDataMapper
import android.slc.appdb.sys.service.CsDictTypeMapper
import android.slc.box.db.service.DbEntityMapper

class DictTypePageVmBox : BaseListPageVmBoxByFx<CsDictType>() {

    override fun onLoadMore() {
        val pageMode = DbEntityMaster.getService(CsDictTypeMapper::class.java).selectByPage(
            loadMoreDataFormatByFx.offset,
            loadMoreDataFormatByFx.size, object : DbEntityMapper.OnSelectConditionListener<CsDictType> {
                override fun onQueryCondition(targetData: CsDictType, queryCondition: CsDictType?): Boolean {
                    return true
                }
            }
        )
        createSlcObserver(loadMoreDataFormatByFx.offset).onNext(SlcEntity.getSlcEntityByData(pageMode))
    }

    fun onSearch() {
        firstRefresh()
    }

    /**
     * 重置搜索
     */
    fun onResetSearch() {
    }

    fun onDelete(csDictType: CsDictType) {
        DbEntityMaster.getService(CsDictTypeMapper::class.java).remove(csDictType)
        DbEntityMaster.getService(CsDictDataMapper::class.java).removeByType(csDictType.dictType)
        firstRefresh()
    }
}